<template>
  <div id="selectionlist">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection/dongyilist' }">动议</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <!--动议内容-->
          <div>
            <el-radio-group v-model="status" @change="changestatus" style="margin:0 0 0 15px" class="pointRadio" v-show="inRoles('ROLE_chuzhang')">
              <el-radio-button label="正在办理的动议" border>
                <el-badge v-if="countnum1>0" :value="countnum1" class="item">正在办理的动议</el-badge>
              </el-radio-button>
              <el-radio-button label="待报出人选" border>
                <el-badge v-if="countnum2>0" :value="countnum2" class="item">待报出人选</el-badge>
              </el-radio-button>
              <el-radio-button label="已退回人选" border>
                <el-badge v-if="countnum3>0" :value="countnum3" class="item">已退回人选</el-badge>
              </el-radio-button>
            </el-radio-group>
            <el-button type="success" @click="dongyi" icon="el-icon-edit" style="margin:15px 0 0 15px;" v-show="inRoles('ROLE_chuzhang')">动议</el-button>
          </div>
          <div>
            <el-table :data="dongyilist" highlight-current-row v-loading="listLoading" style="width: calc(100% - 40px);margin:15px" border>
              <el-table-column label="创建时间" width="200">
                <template slot-scope="scope">
                  {{dateFtt("yyyy-MM-dd hh:mm:ss",scope.row.createTime)}}
                </template>
              </el-table-column>
              <el-table-column label="状态" width="120">
                <template slot-scope="scope">
                  <span v-show="scope.row.state===0">未确定人选</span>
                  <span v-show="scope.row.state===1">已确定人选</span>
                </template>
              </el-table-column>
              <el-table-column prop="personsName" label="人选列表">
              </el-table-column>
              <el-table-column label="操作" width="150">
                <template slot-scope="scope">
                  <el-button @click="edit(scope.row.changeId)" type="primary">进入</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!--动议内容结束-->
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      status: '正在办理的动议',
      dongyilist: [
      ],
      listLoading: false,
      changeSizeFlag: false,
      countnum1: 0,
      countnum2: 0,
      countnum3: 0,
      tableHeight: 100
    }
  },
  methods: {
    dongyi () {
      this.$router.push({path: '/selection/dongyi/0'})
    },
    edit (id) {
      this.$router.push({path: '/selection/dongyi/' + id})
    },
    getList () {
      this.listLoading = true
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/change/getPersonGroupedList`)
        .then(response => {
          this.listLoading = false
          this.dongyilist = response.data.result
          this.changeSizeFlag = false
        })
        .catch(function (error) {
          this.listLoading = false
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.getNums()
    },
    getNums () {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/statnum/change/getStatNum`)
        .then(response => {
          if (response.data.success) {
            this.countnum1 = response.data.result.countnum1
            this.countnum2 = response.data.result.countnum2
            this.countnum3 = response.data.result.countnum3
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    dateFtt (fmt, date) { // author: meizz\
      if (date) {
        let mydate = new Date(date)
        var o = {
          'M+': mydate.getMonth() + 1, // 月份
          'd+': mydate.getDate(), // 日
          'h+': mydate.getHours(), // 小时
          'm+': mydate.getMinutes(), // 分
          's+': mydate.getSeconds(), // 秒
          'q+': Math.floor((mydate.getMonth() + 3) / 3), // 季度
          'S': mydate.getMilliseconds() // 毫秒
        }
        if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (mydate.getFullYear() + '').substr(4 - RegExp.$1.length)) }
        for (var k in o) {
          if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) }
        }
        return fmt
      } else {
        return null
      }
    },
    changestatus () {
      if (this.status === '待报出人选') {
        this.$router.push({path: '/selection/dongyihou/'})
      }
      if (this.status === '已退回人选') {
        this.$router.push({path: '/selection/dongyifinish/'})
      }
    },
    inRoles (str) {
      console.log(str)
      let arr = JSON.parse(localStorage.getItem('Roles'))
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    this.getList()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  #selectionlist .wboxnoborder .el-table{
    border: #95B8E7 solid 1px;
  }
  #selectionlist .wboxnoborder .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
    border-right: #95B8E7 solid 1px;
    border-bottom: #95B8E7 solid 1px;
    min-height: 30px;
    line-height:30px;
  }
  #selectionlist .wboxnoborder .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体';
    text-align: center;
  }
  #selectionlist .el-table__row{
    height: 50px;
  }
</style>
<style scoped>
  .workflowmsg ul{
    background:#F5F7FA;
    margin:0 20px 20px;
    padding:10px 0;
  }
  .workflowmsg li{
    padding:0;
    list-style: none;
    margin-left:20px;
    line-height: 200%;
    font-size:var(--size) !important;
  }
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  h3{
    font-size:var(--size16) !important;
    font-weight: bolder;
    padding-left: 20px;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  #selectionlist .wboxnoborder{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    margin:0 10px;
    overflow: hidden;
  }
</style>
